<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .d2{
            width: 100px;
            height: 100px;
            background-color: rgb(42, 71, 165);
        }
        .d1{
            margin-top: 200px;
            width: 200px;
            height: 200px;
            background-color: brown;
        }
    </style>
</head>
<body>
    <div class="d2">
        哈哈哈
    </div>
    <script>
        var box = document.querySelector('div');
        box.onclick = function(){
            this.className = 'd1'
        }
    </script>
</body>
</html> 